import coordtransform from 'coordtransform'
import { httpUrl } from 'api/config'
import { ajax } from 'api/axios'

export const getLocation = (lng, lat) => {
  return new Promise((resolve, reject) => {
    const wgs84togcj02 = coordtransform.wgs84togcj02(lng, lat)
    const changeGeo = coordtransform.gcj02tobd09(wgs84togcj02[0], wgs84togcj02[1])

    const url = 'http://api.map.baidu.com/geocoder/v2/'

    const data = {
      ak: 'bM5wNuOrapPqqwjLxTV90q4vonw6IVYR',
      location: `${changeGeo[1]},${changeGeo[0]}`,
      output: 'json'
    }

    wx.request({
      url,
      data,
      success: res => {
        resolve(res.data)
      },
      fail: err => {
        resolve({
          msg: err
        })
      }
    })
  })
}

export const getRole = () => {
  const url = `${httpUrl}/listMobileMenu`

  const data = {}

  return ajax(url, data)
}
